#e
#Title[Wonder Years]
#Text[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\lib_anime_tewi.txt"
	#include_function ".\boss.txt"
	let csd		=GetCurrentScriptDirectory;
	let shotData	=csd ~ ".\shot.txt";
	let imgBoss	=csd ~ "img\dot_tewi.png";
	let imgBG1	=csd ~ "img\maho1.png";
	let imgBG2	=csd ~ "img\maho2.png";
	let BGn		=0;
	let xIni	=GetCenterX;
	let yIni	=GetClipMinY + 100;
	@Initialize {
        CutIn(YOUMU,"Wonder Years", "", 0, 0, 0, 0);
        SetLife(2800);
	SetTimer(60);
	SetScore(100000);
	SetDamageRate(5, 5);
	InitializeAction();
	LoadUserShotData(shotData);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBG1);
	LoadGraphic(imgBG2);
	TMain;
	}

	@MainLoop {
	BGn++;
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	yield;
	}

	@DrawLoop {
	SetColor(255,255,255);
	SetGraphicScale(1,1);
	SetAlpha(255);
	SetGraphicAngle(0,0,0);
	DrawBoss(imgBoss);
	BG;
	}

	@Finalize{
	}

function wait(w) {
    loop(w) { yield; }
}
    task TMain {
        yield;
SetDamageRate(80,100);
moveA(90,0);
wait(90);
shotA;
moveA(180,0);
wait(180);
let F=1;
moveA(240,0);
loop(4){
shotB(F);
wait(30);
shotB(-F);
wait(30);
F+=1;
}
wait(60);
shotD;
loop{
moveA(120,0);
shotC;
}





}

task shotA{
let A=0;
let B=0;
let C=0;
loop(6){
A=12;
B=C;
loop(360/A){
CreateShot01(GetX+cos(B-15)*40,GetY+sin(B-15)*20,3.9,B,14,10);
CreateShot01(GetX+cos(B+15)*40,GetY+sin(B+15)*20,3.9,B,14,10);
CreateShot01(GetX+cos(B)*40,GetY+sin(B)*20,4,B,14,10);
B+=A;
}
A=8;
B=C;
loop(360/A){
CreateShot01(GetX+cos(B)*40,GetY+sin(B)*20,3.5,B,22,10);
B+=A;
}
wait(30);
C+=6;
}
}

task shotB(an){
let A=0;
let B=0;
let C=90;
let D=90;
let E=0;
loop(15){
B=C-120;
while(B<C+121){
D=E-3;
while(D<E+4){
CreateShot01(GetX+cos(B)*60,GetY+sin(B)*40,6+A,B+D,62,10);
D+=3;
}
B+=20;
}
wait(2);
C+=0.5*an;
A+=0.05;
}
}

sub shotC{
let A=0;
let B=40;
loop(140){
wait(1);
A=GetAngleToPlayer-B;
while(A<GetAngleToPlayer+B+1){
CreateShot01(GetX+cos(A)*40,GetY+sin(A)*40,rand(2,3.5),A+rand(-20,20),14,10);
A+=B*2;
}
}
}

task shotD{
let A=0;
let B=40;
loop{
wait(70);
CreateEnemyFromScript("FamA",GetX+cos(GetAngleToPlayer+B)*40,GetY+sin(GetAngleToPlayer+B)*40,3,GetAngleToPlayer+B+rand(-15,15),1);
wait(70);
CreateEnemyFromScript("FamA",GetX+cos(GetAngleToPlayer-B)*40,GetY+sin(GetAngleToPlayer-B)*40,3,GetAngleToPlayer-B+rand(-15,15),1);
}
}


   task moveA(wa,waa) {
	wait(waa);
	let wMove =wa;
	SetAction(ACT_MOVE,wMove);
	moveToPlayer(rand(40, 120), rand(-40, 40), wMove,
		GetClipMinX + 48, GetClipMinY +  40,
		GetClipMaxX - 48, GetClipMinY + 90);
	wait(wMove);
	}

function GetGapAngle(
	let x1,
	let y1,
	let x2,
	let y2
){
	return atan2(y2-y1,x2-x1);
}

    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;
        if(GetPlayerX < GetX) {
            x = GetX - xMove;
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            x = GetX + xMove;
            if(right < x) {
                x = GetX - xMove;
            }
        }
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }
}

}

script_enemy FamA {
	let csd		=GetCurrentScriptDirectory;
	let shotData	=csd ~ "shot.txt";
	let imgEy	=csd ~ "img\hks.png";
	let Angle	=GetAngle;
	let Alp		=0;
	let L		=0;

   @Initialize {
        SetLife(2000);
	SetDamageRateEx(100,100,40,0);
	SetScore(1000);
	LoadGraphic(imgEy);
	LoadUserShotData(shotData);
	SetTexture(imgEy);
	TMain;
	}

    @MainLoop {
	if(GetY>=490){VanishEnemy;}  
	SetCollisionA(GetX,GetY,16);
	yield;
	}

	@DrawLoop
	{
	SetGraphicRect(0,0,120,120);
	SetGraphicAngle(0,0,Angle);
	SetColor(255,255,255);
	SetAlpha(Alp);
	SetTexture(imgEy);
	DrawGraphic(GetX,GetY);
	}

    task TMain {
        yield;
Line;
IDOUA;
shotC;
}

task Line{
loop(10){
Alp+=25.5;
wait(1);
}
L=1;
}

sub shotC{
let A=0;
loop(2){
wait(40);
A=GetAngle-130;
while(A<GetAngle+131){
CreateShot01(GetX+cos(A+180)*90,GetY+sin(A+180)*90,2.5,A,62,30);
A+=1.3;
}
}
}

task IDOUA{
loop{
wait(1);
SetSpeed(3);
SetAngle(GetAngle);
}
}

function GetGapAngle(
	let x1,
	let y1,
	let x2,
	let y2
){
	return atan2(y2-y1,x2-x1);
}

function wait(w) {
    loop(w) { yield; }
}
}